package com.caiden_micheal.dynamic.form.mapper;

import com.caiden_micheal.dynamic.form.domain.DynamicForm;
import com.caiden_micheal.dynamic.form.dto.FindDFormPageQueryDTO;
import com.caiden_micheal.dynamic.form.vo.FormSelectDataVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface DFormMapper {

    void insertForm(DynamicForm dynamicForm);

    List<DynamicForm> findFormPageQueryCondition(FindDFormPageQueryDTO findDFormPageQueryDTO);

    Integer findFormPageQueryConditionCount(FindDFormPageQueryDTO findDFormPageQueryDTO);

    @Select("SELECT * FROM sys_dynamic_form WHERE id=#{id}")
    DynamicForm findById(Long id);

    void updateForm(DynamicForm dynamicForm);

    @Select("SELECT * FROM sys_dynamic_form WHERE display_name=#{displayName}")
    DynamicForm findByDisplayName(String displayName);

    @MapKey("id")
    Map<Long, Map<String, String>> findMapByIdList(@Param("formIdList") List<Long> formIdList);

    @Select("SELECT * FROM sys_dynamic_form WHERE display_name LIKE CONCAT('%',#{displayName},'%') ORDER BY create_time DESC LIMIT 0,20")
    List<FormSelectDataVO> findFormSelectData(String displayName);

    @Delete("DELETE FROM sys_dynamic_form WHERE id=#{id}")
    void removeDForm(Long id);
}
